/**
 * @Author: Hhx06
 * @Email: huangshm@yoozoo.com
 * @Description:
 * @File:  main
 * @Version: 1.0.0
 * @Date: 2022/05/25 18:07
 */

package main

import (
	"flag"
	"httpTemplate/cache"
	"httpTemplate/client"
	"httpTemplate/log"
	"httpTemplate/message"

	//"fullLinkObFix/message"
	"math/rand"
	"time"

	"github.com/eyotang/boomer"
)

func worker(ctx boomer.Context, c *client.Client) {
	message.Req(ctx, c)
	return

}

func main() {
	flag.Parse()
	log.Init()
	cache.Init()

	taskInit := &boomer.Task{
		Weight: 0,
		Name:   "init",
		Fn: func(ctx boomer.Context) {
			c := client.NewClient()
			ctx.Set("conn", c)
			//redis获取
			r := cache.GetRedis()
			defer r.Close()
			incr, err := r.Incr("rInt")
			if err != nil {
				return
			}
			ctx.Set("rInt", int(incr))
			rand.Seed(time.Now().Unix())
		},
	}

	d := &boomer.Task{
		Name: "http",
		Fn: func(ctx boomer.Context) {
			v, _ := ctx.Get("conn")
			worker(ctx, v.(*client.Client))
			panic(boomer.StopUser)
		},
	}

	tasks := []*boomer.Task{d}

	boomer.SetInitTask(taskInit)
	boomer.Run(tasks...)
	//b := boomer.NewStandaloneBoomer(3, 1)
	//b.SetInitTask(taskInit)
	//b.Run(tasks...)

}
